package cn.nfwx.tv.adapter;

import android.graphics.Color;
import android.os.Parcelable;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import cn.nfwx.tv.R;
import cn.nfwx.tv.model.CompanyVideo;
import cn.nfwx.tv.model.TvProgram;
import cn.nfwx.tv.util.GlideUtil;
import cn.nfwx.tv.util.LogUtil;

/**
 * Created by zb.liu on 2017/11/1.
 */

public class HotVideoAdapter extends BaseQuickAdapter<Parcelable, BaseViewHolder> {

    public HotVideoAdapter() {
        super(R.layout.fragment_hotvideo_item);
    }


    @Override
    protected void convert(BaseViewHolder helper, Parcelable parcelable) {
        if (parcelable instanceof TvProgram) {
            TvProgram item = (TvProgram) parcelable;
            helper.setText(R.id.tv_hotvideo_name, item.getProgram_name());
            int rid = R.mipmap.video_placeholder;
            GlideUtil.loadRoundImage(helper.getConvertView().getContext(), item.getSnap(), (ImageView) helper.getView(R.id.iv_hotvideo_img), R.dimen.dp2, rid, GlideUtil.ScaleType.CENTER_CROP);
        } else if (parcelable instanceof CompanyVideo) {
            CompanyVideo video = (CompanyVideo) parcelable;
            helper.setText(R.id.tv_hotvideo_name, video.getTitle());
            TextView tv_hotvideo_name = helper.getView(R.id.tv_hotvideo_name);
            tv_hotvideo_name.setTextColor(Color.BLACK);
            String url = video.getUrl();
            int lastIndex = url.lastIndexOf(".");
            url = url.substring(0, lastIndex) + ".jpg";
            int rid = R.mipmap.video_placeholder;
            GlideUtil.loadRoundImage(helper.getConvertView().getContext(), url, (ImageView) helper.getView(R.id.iv_hotvideo_img), R.dimen.dp2, rid, GlideUtil.ScaleType.CENTER_CROP);
        }
    }

}
